package com.hcrazy.manchester.app.services;

import java.util.List;

import com.hcrazy.manchester.app.jdbc.FoodTypeDAO;
import com.hcrazy.manchester.app.pojo.ErrorMsg;
import com.hcrazy.manchester.app.pojo.FoodType;
import com.hcrazy.manchester.app.pojo.PageModel;
import com.hcrazy.manchester.app.utils.Constant;

public class FoodTypeService {

	private FoodTypeDAO foodTypeDAO;
	
	public FoodTypeDAO getFoodTypeDAO() {
		return foodTypeDAO;
	}

	public void setFoodTypeDAO(FoodTypeDAO foodTypeDAO) {
		this.foodTypeDAO = foodTypeDAO;
	}

	public ErrorMsg addOrUpdateFoodType(FoodType foodType) throws Exception{
		ErrorMsg msg = new ErrorMsg();
		msg.setCode(Constant.SUCCESS);//success
		
		if(foodType.getTypeId() > 0){
			foodTypeDAO.updateFoodType(foodType);
		}else{
			foodTypeDAO.addFoodType(foodType);
		}
		
		return msg;
	}
	
	public PageModel getFoodTypes(PageModel model,String search) throws Exception{
		return foodTypeDAO.getPagedFoodTypes(model, search);
	}
	
	public FoodType getFoodTypeById(long foodTypeId) throws Exception{
		return foodTypeDAO.getFoodTypeById(foodTypeId);
	}
	
	public void delFoodType(long foodTypeId) throws Exception{
		foodTypeDAO.deleteFoodType(foodTypeId);
	}
	
	public List<FoodType> getAllFoodTypes() throws Exception{
		return foodTypeDAO.getList();
	}
}
